﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace EFCore反向工程;

public partial class EfcoreDemoDbContext : DbContext
{
    public EfcoreDemoDbContext()
    {
    }

    public EfcoreDemoDbContext(DbContextOptions<EfcoreDemoDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Bird> Birds { get; set; }

    public virtual DbSet<Dog> Dogs { get; set; }

    public virtual DbSet<TBook> TBooks { get; set; }

    public virtual DbSet<TCat> TCats { get; set; }

    public virtual DbSet<TPerson> TPersons { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Data Source=(localdb)\\ProjectModels;Initial Catalog=EFCoreDemoDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Bird>(entity =>
        {
            entity.Property(e => e.Id).ValueGeneratedNever();
        });

        modelBuilder.Entity<TBook>(entity =>
        {
            entity.ToTable("T_Books");

            entity.Property(e => e.AuthorName)
                .HasMaxLength(20)
                .HasDefaultValue("");
            entity.Property(e => e.Title).HasMaxLength(50);
        });

        modelBuilder.Entity<TCat>(entity =>
        {
            entity.ToTable("T_Cats");

            entity.Property(e => e.Name).HasMaxLength(22);
        });

        modelBuilder.Entity<TPerson>(entity =>
        {
            entity.ToTable("T_Persons");

            entity.HasIndex(e => e.Name, "IX_T_Persons_Name");

            entity.Property(e => e.BirthPlace).HasDefaultValue("中国");
            entity.Property(e => e.Salary).HasDefaultValue(2000.0);
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
